const utils = require('../../utils/util.js');
const commonUtil = require('../../utils/common.js');
Page({
  data: {
    _userInfo: null,
    // lists: [
    //   {name: '用户名', action: 'username', arrow: true},
    //   {name: '修改密码', action: 'modifyPsw', arrow: true},
    //   {name: '修改手机号', action: 'modifyPhone', arrow: true},
    //   {name: '绑定微信', action: 'bindWechat', arrow: true},
    //   {name: '退出登录', action: 'logout', arrow: false},
    // ],
  },
  onLoad(options) {},
  onReady() {},
  onShow() {
    if (typeof this.getTabBar === 'function' &&  this.getTabBar()) {
      this.getTabBar().setData({
        selected: 4
      })
    }
    commonUtil.getLoginUser();
    let that = this;
    setTimeout(()=>{
      let userInfo = wx.getStorageSync('userInfo');
      if (userInfo != undefined) {
        userInfo.safePhoneNumber = utils.safePhoneNumber(userInfo.phoneNumber)
        that.setData({_userInfo: userInfo});
      }
    }, 200)
    this.removeStorage()
  },
  removeStorage(){
    // wx.removeStorageSync('currentQuote');
    wx.removeStorageSync('currentMenu');
    wx.removeStorageSync('currentSub');
    wx.removeStorageSync('detailBack');
  },
  listItemTap(e){
    let currentAction = e.currentTarget.dataset.action;
    console.log(currentAction);
    console.log(this.data._userInfo.setPassword);
    if (currentAction == 'username') {
      wx.navigateTo({
        url: '/packageA/pages/setUsername/index',
      })
    } else if (currentAction == 'modifyPsw') {
      wx.navigateTo({
        url: '/packageA/pages/resetPsw/index',
      })
    } else if (currentAction == 'modifyPhone') {
      wx.navigateTo({
        url: '/packageA/pages/modifyPhone/index',
      })
    } else if (currentAction == 'bindWechat') {
      wx.navigateTo({
        url: '/packageA/pages/bindWechat/index',
      })
    } else if (currentAction == 'logout') {
      wx.removeStorageSync('token')
      wx.removeStorageSync('tokenExpire')
      wx.removeStorageSync('userInfo')
      wx.removeStorageSync('userService')
      wx.switchTab({
        url: '/pages/index/index',
      })
    }
  },
  onUnload() {},
})